from django.db import models

# Create your models here.
from users.models import User


class NewsCategories(models.Model):
    category_name = models.CharField(max_length=64,verbose_name="分类名称")
    is_delete = models.BooleanField(default=False,verbose_name='是否删除')

    class Meta:
        db_table = 'tb_category'
        verbose_name = '专栏分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category_name


class News(models.Model):
    title =models.CharField(max_length=128,verbose_name="新闻标题")
    digest=models.TextField(verbose_name="摘要")
    create_time=models.DateTimeField(verbose_name="创建时间")
    concent=models.TextField(verbose_name="文章内容")
    click_count=models.IntegerField(verbose_name="点击量")
    comment_conut=models.IntegerField(verbose_name="评论量")
    image=models.CharField(max_length=64,null=True,verbose_name="图片")
    tag=models.CharField(max_length=64,verbose_name='标签')
    category=models.ForeignKey(NewsCategories,on_delete=models.CASCADE,verbose_name="分类")
    user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name="用户")
    # tag_id=models.ForeignKey()

    class Meta:
        db_table = 'tb_news'
        verbose_name = '头条'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Comment(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    news_id = models.ForeignKey(News, on_delete=models.CASCADE, verbose_name='新闻')
    content = models.TextField(verbose_name='评论内容')
    create_time = models.DateField(verbose_name='评论时间')
    count = models.IntegerField(verbose_name='评论量')

    class Meta:
        db_table = 'tb_news_comment'
        verbose_name = '新闻评论'
        verbose_name_plural = verbose_name


class Sub_Comment(models.Model):
    content = models.TextField(verbose_name='评论内容')
    count = models.IntegerField(verbose_name='评论量')
    create_time = models.DateField(verbose_name='评论时间')
    parent_id = models.ForeignKey('self', on_delete=models.CASCADE,verbose_name='子评论的父评论')
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    comment_id = models.ForeignKey(Comment, on_delete=models.CASCADE, verbose_name='父评论')

    class Meta:
        db_table = 'tb_sub_comment'
        verbose_name = '新闻子评论'
        verbose_name_plural = verbose_name


class Collections(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='作者')
    news_id = models.ForeignKey(News, on_delete=models.CASCADE, verbose_name='新闻')

    class Meta:
        db_table = 'tb_news_collection'
        verbose_name = '收藏'
        verbose_name_plural = verbose_name



class Authorfollow(models.Model):
    author=models.ForeignKey(User,on_delete=models.CASCADE,related_name="fucus_user",verbose_name='作者')
    user=models.ForeignKey(User,on_delete=models.CASCADE,related_name="pub_author",verbose_name='用户')
    class Meta:
        db_table='tb_news_followed'
        verbose_name = '关注作者'
        verbose_name_plural = verbose_name
